-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Introduce reverse
methods in AOP MethodMatchers
and ClassFilters
#26725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it simpler to do "Logical NOT" on the results of the matches() of the original filter? Could you give me an example of how these classes can be useful?
@cuspymd Thanks for the reply. public class Example {
/**
* this FeignClient require logging
*/
@FeignClient("svr-name")
public interface Client extends Api {
}
/**
* this FeignClient does not require logging
*/
@LogIgnore
@FeignClient("svr-name")
public interface IgnoreClient extends Api {
}
/**
* in other Jar
*/
interface Api {
/**
* this method does not require logging
*/
@LogIgnore
@RequestMapping("/ignoreApi")
void ignoreApi();
/**
* this method require logging
*/
@RequestMapping("/api")
void api();
}
/**
* Annotated classes or methods do not need to be logged
*/
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@interface LogIgnore {
}
/**
* The Advisor for Feign
*/
public class FeignAdvisor extends AbstractPointcutAdvisor {
@Override
public Pointcut getPointcut() {
return new Pointcut() {
@Override
public ClassFilter getClassFilter() {
//This class mast contain @FeignClient
ClassFilter cf1 = new AnnotationClassFilter(FeignClient.class, true);
//This class cannot contain @LogIgnore
ClassFilter cf2 = ClassFilters.reversion(new AnnotationClassFilter(LogIgnore.class, true));
//maybe more ClassFilter
return ClassFilters.intersection(cf1, cf2);
}
@Override
public MethodMatcher getMethodMatcher() {
//This method mast contain @RequestMapping
MethodMatcher cf1 = new AnnotationMethodMatcher(RequestMapping.class, true);
//This method cannot contain @LogIgnore
MethodMatcher cf2 = MethodMatchers.reversion(new AnnotationMethodMatcher(LogIgnore.class, true));
//maybe more MethodMatcher
return MethodMatchers.intersection(cf1, cf2);
}
};
}
@Override
public Advice getAdvice() {
//do something
return (MethodInterceptor) (MethodInvocation invocation) -> invocation.proceed();
}
}
} |
Thanks for the detailed explanation. It looks very useful. |
Polish
@rstoyanchev Could you please have a look into this? |
Hi, I am a beginner with Open source contributions. This would be my first contribution, can anyone please guide me through it? |
@Pulkit-Garg15 thanks for the offer but this is already a PR (see the "Files Changed" tab above) so this isn't open for contribution. |
I think a |
I agree. It's analogous to Along the same lines, I could see it being useful to have something like the static
I imagine that could be handy in
The filters are used to differentiate pointcuts -- for example, in |
reverse
methed in AOP MethodMatchers
and ClassFilters
reverse
methed in AOP MethodMatchers
and ClassFilters
reverse
metheds in AOP MethodMatchers
and ClassFilters
Such a shame that we can't do the |
@Jinhui-Z thanks very much for making your first contribution to Spring Framework. |
This seems to have been shipped with 6.1.0-M5 but doesn't have a milestone. There's also a typo in "metheds" in the title. |
reverse
metheds in AOP MethodMatchers
and ClassFilters
reverse
methods in AOP MethodMatchers
and ClassFilters
Good catch @izeye. I've fixed the title and added the missing entry manually to the release notes. |
Add reverse methed in MethodMatchers and ClassFilters.
Add support for MethodMatchers and ClassFilters to reverse the given MethodMatcher and ClassFilter.
It is convenient in some complex conditions,Or is there another way to do it?Thanks.